#include "ComputeRunTime.h"
#include "NGLog.h"

//-----------------------------------
ComputeRunTime::ComputeRunTime(string name) : m_strName(name), m_beginTime(0)
{}
//-----------------------------------
bool ComputeRunTime::Start()
{
	Log.Debug(m_strName.c_str(), "-------------begin compute run time (ms)...");
	m_beginTime = GetMSOfCurTime();
	return m_beginTime;
}
//-----------------------------------
bool ComputeRunTime::End()
{
	long endTiem = GetMSOfCurTime();
	long offset = endTiem - m_beginTime;
	if (offset < 0)
		return false;
	Log.Debug(m_strName.c_str(), "-------------end compute, time offset = %d ms", offset);
	return true;
}
//-----------------------------------
long ComputeRunTime::GetMSOfCurTime()
{
	struct timezone tz;
	timeval tv;
	if (0 == gettimeofday(&tv, &tz))
	{
		return tv.tv_sec * 1000 + tv.tv_usec / 1000;
	}
	Log.Error("ComputeRunTime::GetMSOfCurTime", "-------------get ms of current time error!!");
	return 0;
} 
